<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="nespresso.beans.*" %>
<%@page import="java.sql.*" %>
<%@page import="java.text.*" %>
<%
Commande c = (Commande)session.getAttribute("commande");
String recapmode = (String)session.getAttribute("RecapMode");
String brecapmode = null;
if(recapmode.equals("Capsules")) { brecapmode = new String("Par utilisateur"); }
if(recapmode.equals("Utilisateurs")) { brecapmode = new String("Par capsule"); }
%>
<html>
<head>
<title>NESPRESSO</title>

<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.17.custom.css" />
<link rel="stylesheet" type="text/css" href="css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="css/nespresso.css" />

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.17.custom.min.js" type="text/javascript"></script>
<script src="js/grid.locale-fr.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.js" type="text/javascript"></script>

<script>

$(function() {
	$( "#tabs" ).tabs();
});

</script>

</head>

<body>
<div class="super-div">
<div id="divrond1">
	<table width="100%">
		<tr height="83px"><td width="50%"></td><td align="center">	
			<p class="grosblancitalique"><b>Récapitulatif</b></p>
		</td></tr>
	</table>
</div>

<form action="Recapitulatif" method="post" name="RecapForm" target="_self">
<div style="width:1020px; text-align:center; padding:10px; margin:auto">
	<font class="moyennoir">COMMANDE N° </font><font class="moyenblanc"><%=c.GetId() %></font>
	<font class="moyennoir">PASSÉE LE </font><font class="moyenblanc"><%=c.GetDate() %></font>
	<br><br>
	<%
	if(recapmode.equals("Capsules")) { %>
	<div id="tabs-Recap" align="center">
		  	<table id="TabRecap" style="font-size:11px;">
  				<tr>
  					<th>Id</th>
  					<th>Nom</th>
  					<th>Total</th>
  				</tr>
  				<tbody>
  					<%
  						String pu = new String(); 
  						String requete = new String("SELECT ID_CAPSULE, NOM, SUM(NOMBRE) AS TOTAL FROM LIGNESCDE L, CAPSULES C WHERE L.ID_CAPSULE=C.ID AND L.ID_COMMANDE='" + c.GetId() + "' GROUP BY ID_CAPSULE");
  						Base bc = new Base();
  						bc.ExecuteRequete(requete);
  						while (bc.Suivant()) {
  							pu = new DecimalFormat("0").format(bc.GetEntier("TOTAL"));
  							%>
  							<tr>
  								<td><%=bc.GetTexte("ID_CAPSULE")%></td>
  								<td><%=bc.GetTexte("NOM")%></td>
  								<td><%=pu%></td>
  							</tr>
  							<%
  						}
  						bc.Free(); %>
			  	</tbody>
  			</table>
  	</div>
  	<% }
  	if(recapmode.equals("Utilisateurs")) { %>
	<div id="tabs-Recap" align="center">
		  	<table id="TabRecap" style="font-size:11px;">
  				<tr>
  					<th>Id</th>
  					<th>Nom</th>
  					<th>Total</th>
  				</tr>
  				<tbody>
  					<%
  						String pu = new String(); 
  						String requete = new String("SELECT ID_USER, NOM, PRENOM, SUM(MONTANT) AS TOTAL FROM LIGNESCDE L, USERS U WHERE L.ID_USER=U.ID AND L.ID_COMMANDE='" + c.GetId() + "' GROUP BY ID_USER");
  						Base bu = new Base();
  						bu.ExecuteRequete(requete);
  						while (bu.Suivant()) {
  							pu = new DecimalFormat("0.00 €").format(bu.GetReel("TOTAL"));
  							%>
  							<tr>
  								<td><%=bu.GetTexte("ID_USER")%></td>
  								<td><%=bu.GetTexte("NOM") + " " + bu.GetTexte("PRENOM") %></td>
  								<td><%=pu%></td>
  							</tr>
  							<%
  						}
  						bu.Free(); %>
			  	</tbody>
  			</table>
  	</div>
  	<% } %>
</div>
<div align="center">
	<input type="submit" name="bcommande" id="bcruser" value="<%=brecapmode%>" class="boutons" /><br><br>
	<input type="submit" name="bcommande" id="bcNew" value="Retour" class="boutons" /><br><br>
</div>
</form>
</div>

<script>
<% if(recapmode.equals("Capsules")) { %>

tableToGrid("#TabRecap", {
    width: 'auto',
    height: "auto",
    hidegrid: false,
    sortname: "Date",
    sortorder: "desc",
	colModel: [{name:'Id', editable:false, width:80},
	           {name:'Nom', editable:false, width:180},
               {name:'Total', editable:false, width:80}],
});

<% }

if(recapmode.equals("Utilisateurs")) { %>

tableToGrid("#TabRecap", {
    width: 'auto',
    height: "auto",
    hidegrid: false,
    sortname: "Date",
    sortorder: "desc",
	colModel: [{name:'Id', editable:false, width:80},
	           {name:'Nom', editable:false, width:350},
               {name:'Total', editable:false, width:80, align:'right'}],
});
<% } %>
</script>
</body>
</html>
